<template>
	<view>
		<navbar title="设置"></navbar>
		<view class="site-box">
			<view class="site-list fa jcsb bbe" @click="utils.navTo('/pages/mine/aboutus')">
				<view>关于我们</view>
				<image class="right-icon" src="../../static/right.png" mode=""></image>
			</view>
			<view class="site-list fa jcsb" @click="checkVersion">
				<view>版本更新</view>
				<image class="right-icon" src="../../static/right.png" mode=""></image>
			</view>
		</view>
		<view class="site-box" v-if="token">
			<view class="site-list fa jcsb" @click="logout">
				<view>退出登录</view>
				<image class="right-icon" src="../../static/right.png" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: ''
			};
		},
		onLoad() {
			this.token = uni.getStorageSync('token')
		},
		methods: {
			checkVersion() {
				const updateManager = uni.getUpdateManager();
				updateManager.onCheckForUpdate(res=>{
					if(res.hasUpdate){
						// updateManager.applyUpdate();
						uni.showToast({
							icon:'none',
							title:"检测到有新版本"
						});
					}else {
						uni.showToast({
							icon:'none',
							title:"已是最新版本"
						});
					}
				});
				updateManager.onUpdateReady(()=>{ uni.showModal({
					title: '更新提示',
					content: '新版本已经准备好，点击确定重新启动',
					showCancel: !1,
					complete:res=>{if(res.confirm)updateManager.applyUpdate();}
				});});
				updateManager.onUpdateFailed(()=>{uni.showModal({
					title: '提示',
					content: '检查到有新版本，但是下载失败，请检查网络',
					showCancel: !1
				});});
			},
			logout() {
				uni.showModal({
					title: '提示',
					content: '是否退出登录？',
					success: result => {
						if(result.confirm) {
							uni.showToast({
								title: '已退出登录'
							})
							uni.clearStorageSync()
							setTimeout(() => {
								uni.navigateBack()
							}, 1500)
						}
					}
				})
			}
		}
	}
</script>
<style>
	page{
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>
	.site-box{
		padding: 0 24rpx;
		border-top: 20rpx solid #F6F6F6;
		.site-list{
			padding: 34rpx 0;
			&.bbe{
				border-bottom: 2rpx solid #F6F6F6;
			}
			.right-icon{
				width: 22rpx;
				height: 22rpx;
			}
		}
	}
</style>
